import { Injectable } from '@angular/core'
import { deepCopy } from '@delon/util'
import { Observable } from 'rxjs'

import { ObservableStore } from '@shared/classes/ObservableStoreClass'
import { OnlineChargeAddModel, OnlineChargeAddSystem } from '@shared/interfaces/trade'
import { TradeService } from '../../trade-abstract.service'
import { StoreInfo } from '@shared/interfaces/trade'

@Injectable()
export class ChargeStoreService extends ObservableStore<OnlineChargeAddModel> {
  constructor(private tradeService: TradeService) {
    super(new OnlineChargeAddModel())
  }

  updateValue(store: OnlineChargeAddModel): void {
    const value = deepCopy(this.value)
    Object.assign(value, store)
    this.setValue(value)
  }

  setSystemValue(systemInfo: OnlineChargeAddSystem): void {
    this.value.systemInfo = systemInfo
    this.setValue(this.value)
  }

  reset(): void {
    this.setValue(new OnlineChargeAddModel())
  }

  getStoreInfo(intStoreCode: string): Observable<StoreInfo> {
    return this.tradeService.getStoreInfo(intStoreCode)
  }
}
